"""
    create by IAmFiveHigh on 2023/10/6
"""
from typing import List


class Solution:
    @classmethod
    def sort_colors(cls, nums: List[int]) -> None:
        less_than = 0
        great_than = len(nums)
        i = 0

        while i < great_than:
            if nums[i] == 0:
                cls._exchange(nums, i, less_than)
                less_than += 1
                i += 1
            elif nums[i] == 1:
                i += 1
            elif nums[i] == 2:
                great_than -= 1
                cls._exchange(nums, i, great_than)

    @staticmethod
    def _exchange(nums: List[int], i: int, j: int):
        temp = nums[i]
        nums[i] = nums[j]
        nums[j] = temp


if __name__ == '__main__':
    nums1 = [2, 0, 1, 2, 1, 0]
    nums2 = [2, 0, 1]

    Solution.sort_colors(nums1)
    print(nums1)

    Solution.sort_colors(nums2)
    print(nums2)
